package utils
{

	import flash.display.*;
	import flash.events.*;

	public class FrameChecker extends Object
	{
		private var bReady:Boolean;
		private var afterHandler:Function;
		private var sLabel:String="";
		private var mc:MovieClip;
		private var nFrame:Number=0;

		public function FrameChecker()
		{
			nFrame=0;
			sLabel="";
			return;
		} // end function

		private function onCheckFrame(event:Event):void
		{
			var evt:*=event;
			try
			{
				if (bReady)
				{
					nFrame=0;
					mc.removeEventListener(Event.ENTER_FRAME, onCheckFrame);
					afterHandler();
				}
				if (mc.currentFrame == nFrame)
				{
					bReady=true;
				}
			}
			catch (error:Error)
			{
				trace("ERROR! " + error.message);
			}
			return;
		} // end function

		public function checkFrame(param1:MovieClip, param2:Number, param3:Function):void
		{
			bReady=false;
			this.mc=param1;
			this.nFrame=param2;
			this.afterHandler=param3;
			param1.addEventListener(Event.ENTER_FRAME, onCheckFrame);
			return;
		} // end function

		private function onCheckLabel(event:Event):void
		{
			var evt:*=event;
			try
			{
				if (bReady)
				{
					sLabel="";
					mc.removeEventListener(Event.ENTER_FRAME, onCheckLabel);
					afterHandler();
				}
				if (mc.currentLabel == sLabel)
				{
					bReady=true;
				}
			}
			catch (error:Error)
			{
				trace("ERROR! " + error.message);
			}
			return;
		} // end function

		public function reset():void
		{
			try
			{
				if (nFrame > 0)
				{
					mc.removeEventListener(Event.ENTER_FRAME, onCheckFrame);
				}
				if (sLabel.length > 0)
				{
					mc.removeEventListener(Event.ENTER_FRAME, onCheckLabel);
				}
			}
			catch (error:Error)
			{
				trace("ERROR! " + error.message);
			}
			return;
		} // end function

		public function checkLabel(param1:MovieClip, param2:String, param3:Function):void
		{
			bReady=false;
			this.mc=param1;
			this.sLabel=param2;
			this.afterHandler=param3;
			param1.addEventListener(Event.ENTER_FRAME, onCheckLabel);
			return;
		} // end function

	}
}
